package cn.lyf.service;

import cn.lyf.dao.AnswerDao;
import cn.lyf.dao.BlogDao;
import cn.lyf.entity.Answer;
import cn.lyf.entity.Blog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    BlogDao blogDao;

    @Autowired
    AnswerDao answerDao;

    //回复博客
    @Override
    public Answer answer2Blog(String blogid, Answer answer) {
        //根据博客id查找博客
        Blog blog = blogDao.findOneBlog(blogid);
        answerDao.addAnswerDao(answer);
        blog.setAnswernum(blog.getAnswernum()+1);
        blogDao.add(blog);
        return answer;
    }

    //根据博客id查找对应的评论
    @Override
    public List<Answer> findAnswersByBlogId(String bloid) {

        return answerDao.findAnswersByBlogid(bloid);
    }

    //根据id查找评论
    @Override
    public Answer findById(String id) {
        return answerDao.findById(id);
    }

    //回复别人的评论
    //group:被回复的评论
    //answer:回复的评论
    @Override
    public Answer answer2Answer(Answer group, Answer answer) {
        answer = answerDao.addAnswerDao(answer);
        answerDao.addAnswerDao(group);
        return answer
                ;

    }
}
